﻿@model StoreModel
@if (!string.IsNullOrEmpty(Model.Id))
{
    <div class="panel panel-default">
        <div class="panel-body">
            <div id="domains-grid"></div>
        </div>
    </div>
    <script>
            $(document).ready(function () {
                $("#domains-grid").kendoGrid({
                    dataSource: {
                        transport: {
                            read: {
                                url: "@Html.Raw(Url.Action("Domains", "Store", new { storeid = Model.Id, area = Constants.AreaAdmin }))",
                                type: "POST",
                                dataType: "json",
                                data: addAntiForgeryToken
                            },
                            create: {
                                url: "@Html.Raw(Url.Action("DomainInsert", "Store", new { storeid = Model.Id, area = Constants.AreaAdmin }))",
                                type: "POST",
                                dataType: "json",
                                data: addAntiForgeryToken
                            },
                            update: {
                                url: "@Html.Raw(Url.Action("DomainUpdate", "Store", new { storeid = Model.Id, area = Constants.AreaAdmin }))",
                                type: "POST",
                                dataType: "json",
                                data: addAntiForgeryToken
                            },
                            destroy: {
                                url: "@Html.Raw(Url.Action("DomainDelete", "Store", new { storeid = Model.Id, area = Constants.AreaAdmin }))",
                                type: "POST",
                                dataType: "json",
                                data: addAntiForgeryToken
                            }
                        },
                        schema: {
                            data: "Data",
                            total: "Total",
                            errors: "Errors",
                            model: {
                                id: "Id",
                                fields: {
                                    Url: { editable: true, type: "string" },
                                    HostName: { editable: false, type: "string" },
                                    Primary: { editable: false, type: "boolean" },
                                }
                            }
                        },
                        requestEnd: function (e) {
                            if (e.type == "create" || e.type == "update") {
                                this.read();
                            }
                        },
                        error: function(e) {
                            display_kendoui_grid_error(e);
                            // Cancel the changes
                            this.cancelChanges();
                        },
                        serverPaging: false,
                        serverFiltering: true,
                        serverSorting: true
                    },
                    pageable: {
                        refresh: true,
                        numeric: false,
                        previousNext: false,
                        info: false
                    },
                    toolbar: [{
                        name: "create",
                        text: "@Loc["Admin.Common.AddNewRecord"]"
                    }, { name: "save", text: "@Loc["Admin.Common.Save"]" }, { name: "cancel", text: "@Loc["Admin.Common.Cancel"]" }],
                    editable: {
                        confirmation: false,
                        mode: "inline",
                    },
                    scrollable: false,
                    columns: [{
                        field: "Url",
                        title: "@Loc["Admin.Configuration.Stores.Domains.Fields.Url"]"
                    },
                    {
                        field: "HostName",
                        title: "@Loc["Admin.Configuration.Stores.Domains.Fields.HostName"]"
                    },
                    {
                        field: "Primary",
                        title: "@Loc["Admin.Configuration.Stores.Domains.Fields.Primary"]",
                        headerAttributes: { style: "text-align:center" },
                        attributes: { style: "text-align:center" },
                        template: '# if(Primary) {# <i class="fa fa-check" aria-hidden="true" style="color:green"></i> #} else {# <i class="fa fa-times" aria-hidden="true" style="color:red"></i> #} #'
                    },
                    {
                        command: [{
                            name: "edit",
                            text: {
                                edit: "@Loc["Admin.Common.Edit"]",
                                update: "@Loc["Admin.Common.Update"]",
                                cancel: "@Loc["Admin.Common.Cancel"]"
                            }
                        }, {
                            name: "destroy",
                            text: "@Loc["Admin.Common.Delete"]"
                        }]
                    }]
                });
            });
    </script>
}
else
{
    <div class="note note-info">
        @Loc["Admin.Configuration.Stores.Domains.SaveBeforeEdit"]
    </div>
}